﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ExcelColumnSplitter
{
    public partial class PresetsForm : Form
    {
        public PresetsForm()
        {
            InitializeComponent();
            foreach(var preset in AppSettings.Instance.Presets)
            {
                PresetsListBox.Items.Add(preset.Key);
            }
        }

        private void PresetsForm_Load(object sender, EventArgs e)
        {
            
        }

        private void PresetsListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadButton.Enabled = (PresetsListBox.SelectedIndex != -1);
        }

        private void RemoveButton_Click(object sender, EventArgs e)
        {
            AppSettings.Instance.Presets.Remove(PresetsListBox.SelectedItem.ToString());
            PresetsListBox.Items.Remove(PresetsListBox.SelectedItem);
            AppSettings.Instance.Save();
        }

        private void LoadButton_Click(object sender, EventArgs e)
        {
            if(PresetsListBox.SelectedIndex == -1)
            {
                return;
            }
            var splitNavigatorForm = new SplitNavigatorForm(AppSettings.Instance.Presets[PresetsListBox.SelectedItem.ToString()])
            {
                StartPosition = FormStartPosition.CenterScreen
            };
            splitNavigatorForm.Show();
            this.Close();
        }
    }
}
